/**
 * @Author：ming
 * @Date：2023/9/26 3:10 PM
 * @Filename：Lc530
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author ming
 */
public class Lc530 {
    public int getMinimumDifference(TreeNode root) {
        ArrayList<Integer> list = new ArrayList<>();
        look(root,list);
        int[] a = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            a[i]=list.get(i);
        }

        int min = Math.abs(a[0]-a[1]);
        for (int i = 0; i < a.length-1; i++) {
            int temp = Math.abs(a[i]-a[i+1]);
            if(temp<min){
                min = temp;
            }
        }
        return min;
    }

    public static void look(TreeNode root, List l){
        if(root.left!=null){
            look(root.left,l);
        }
        l.add(root.val);

        if(root.right!=null){
            look(root.right,l);
        }
    }
}
